/**
 * @Description: 自定义返回类
 * @author zhaojiuyi
 * @date 2023/4/7
 */

import {HttpStatus} from "@nestjs/common";
import {ApiProperty} from "@nestjs/swagger";


export interface ResultConfig<T> {
    code: HttpStatus
    data: T,
    msg: string
}

export class AjaxResult<U> {

    private constructor(config: ResultConfig<U>) {
        Object.assign(this, config);
    }

    static success<U = object | string | number | null>(data = null, msg = "success") {
        return new AjaxResult<U>({code: HttpStatus.OK, data, msg});
    }

    static error(code = HttpStatus.INTERNAL_SERVER_ERROR, msg = "服务器内部错误") {
        return new AjaxResult<null>({data: null, code, msg});
    }
}

